<?php

/* liweile
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of doRedis
 *
 * @author ggg
 */
class ZRedis {
    /**
     * 用户的信息
     * @var type 
     */
    public $user_list;
    /**
     * 用户关系表
     * @var type 
     */
    public $usertouser_list;
    /**
     * 用户关注我的
     * @var type 
     */
    public $usertome;
    /**
     * 我关注用户的
     * @var type 
     */
    public $metouser;
    /**
     * 实例化redis
     * @var type 
     */
    public $redis;
    /**
     * 我和用户之间的关系
     * @var type 
     */
    public $metootherInfo;
    /**
     * 通过aa获取分享的详细信息
     * @var type 
     */
    public $aatoitem;
    /**
     * 分享的列表
     * @var type 
     */
    public $item_list;
    /**
     * 获取item的评论数
     * @var type 
     */
    public $itemtoComNums;
    /**
     * 获取item的转发数
     * @var type 
     */
    public $itemtoShNums;
    /**
     * item的评论
     * @var type 
     */
    public $itemtocomment;
    /**
     * 评论列表
     * @var type 
     */
    public $comment_list;
    /**
     * aa获取我收到评论
     * @var type 
     */
    public $aaGetComment;
    /**
     * aa获取我发出的评论
     * @var type 
     */
    public $aaComCommet;
    /**
     * aa的热评
     * @var type 
     */
    public $aa2hot;
	
    //public $ip='117.79.228.71';
    public $ip = '192.168.1.15';
    public $ip_port = 6379;
    
    public function __construct(){
        $this->user_list = 'user::list';
        $this->usertouser_list= 'user::usertouser:list';
        $this->usertome = 'user::usertome:';
        $this->metouser = 'user::metouser:';
        $this->metootherInfo = 'user::metootherInfo:';
        $this->searchaatouser = 'user::sharchme:';
                
        
        $this->aatoitem = 'share:aatoitem:';
        $this->item_list = 'Share::item:list';
        $this->itemtoComNums = 'share::itemtoComcount:list';
        $this->itemtoShNums = 'share::itemtoShCount:list';
        $this->itemtocomment = 'share::itemtoComment:';
        $this->aatoitemtoother = 'share::aatoitemtoother:';
        
        $this->comment_list = 'Share::comment:list';
        $this->aaGetComment = 'share::aaGetComment:';
        $this->aaComCommet = 'share::aaComComment:';
        $this->aatohot = 'share:aatohot:';
        $this->aatootherUser = 'aatootherItem';
		
        $this->schooltomsg = 'msg::schooltomsg:list:';//msg::schooltomsg:list:{1222012}
        //"{sechool—id}::{学期}:{$aa}:{新闻/通知的id}" 学校里面用户的不同类型的message
        $this->msgtocomNums = 'msg::school:msgtocomUnms:list:';
        $this->msgtotransmitNums = 'msg::schooltomsgtotransmitNums:list:';
        $this->schtorange = 'msg::schooltorange:';//hash msg::schooltorange:1222012 0_0_0_0_0 100501
        $this->msgComment = 'msg::msgtocomment:';//msg::msgtocomment:学校 hash 
        //"msg::{school}:msgtocom:{msg_id}" 存储msg和评论的关系列
        //$this->msgtocomment = 'msg::';
        $this->aatorange = 'user::aatorange:list';
        $this->aatomsg = 'msg::aatomsg:';
        $this->msgtocat = 'msg::msgCat:list:';
        
        $this->wattingsql = 'sql::watting:list';
        $this->redis = new Redis();
        $this->redis->connect($this->ip,$this->ip_port);
    }
    //添加sql列
    public function addWaitSql($sql){
        if(empty($sql)) return false;
        $this->redis->sadd($this->wattingsql,$sql);
    }
    //获取我的消息
    public function floowme(){
        $floowme = array(
            '1' => '消息',
            '2' => '关注我的',
            '3' => 'test'
        );
        $list = array();
        foreach($floowme as $k => $name){
            $info = $this->getIfo(1100001,100501,$k);
            if($info['count']){
                $list[$k] = array(
                    'count' => $info['count'],
                    'name' => $name,
                    'list' => $info['list'],
                    'url' => '/flowme/tp/'.$k,
                );
            }
        }
        echo json_encode($list);
    }
    //添加到我的消息
    public function addFlowme($school, $me, $type, $val){
        if(empty($school) || empty($me) || empty($type) || empty($val)) return false;
        $fix = "msg::aatomsg:{$school}:{$me}:{$type}";
        $this->redis->sadd($fix, $val);
    }
    //获取我的消息
    public function getIfo($school,$aa,$type){
        if(empty($school) || empty($aa) || empty($type))
            return false;
        $fix = "msg::aa2msg:{$school}:{$aa}:{$type}";
        $info = $this->redis->smembers($fix);
        $newlist = array();
        foreach ($info as $row){
            $row = unserialize($row);
            $newlist[] = $row; 
        }
        return array('list' => $newlist,'count'=>$this->redis->scard($fix));
    }
    
    public function setRole($school,$role,$aa,$val){
        if(empty($school) || empty($aa) || empty($val))
            return false;
        return $this->redis->set("school::role:{$school}:{$role}:{$aa}",$val);

    }
    public function getRole($school,$role,$aa,$val){
        if(empty($school) || empty($aa) || empty($val))
            return false;
        return $this->redis->get("school::role:{$school}:{$role}:{$aa}");
    }
    
}
?>
